﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DataManager;
using DataManager.TablesManager;

namespace MessagesTool
{
    public partial class Home : Form
    {
        public Home()
        {
            InitializeComponent();
        }

        private void btnSignUp_Click(object sender, EventArgs e)
        {
            ACCOUNT ac = new ACCOUNT();
            ac.FRIEND = "";
            ac.FULLNAME = txtFullName.Text;
            ac.USERID = txtUserName.Text;
            ac.PASS = Library.EncodePassword(txtPassword.Text);
            if (new AccountManager().Insert(ac))
                MessageBox.Show("Thành Công!!!");
            else
                MessageBox.Show("Thất Bại!!!");
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            ACCOUNT ac = new AccountManager().SelectByID<ACCOUNT>("ThanhKhoaIT");
            txtFullName.Text = ac.FULLNAME;
        }

        private void Home_Load(object sender, EventArgs e)
        {
            DataManager.Logs.Path = Application.StartupPath;
        }

        private void btnUpdate_Click(object sender, EventArgs e)
        {
            if(new MessModule.Account().Add_Friend("test", "ThanhKhoaIT"))
                MessageBox.Show("Thành công!!!");
            else
                MessageBox.Show("Thất bại!!!");
        }

        private void btnRemove_Click(object sender, EventArgs e)
        {
            if (new MessModule.Account().Remove_Friend("ThanhKhoaIT", "test"))
                MessageBox.Show("Thành công!!!");
            else
                MessageBox.Show("Thất bại!!!");
        }

        private void btnLoadAll_Click(object sender, EventArgs e)
        {
            List<string> data = new MessModule.Messages().Get("Test", "thanhkhoait");
            if (data != null)
            {
                for (int j = 0; j < data.Count; j++)
                {
                    listBox1.Items.Add(data[j]);
                }
            }
            
        }
    }
}
